package com.example.intelligentattendancesystem.mapping;

import com.example.intelligentattendancesystem.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * user的持久化
 */
@Mapper
public interface UserMapping {
    /**
     * 新增用户
     * @param user
     * @return 修改的条数
     */
    @Insert("insert into t_user values(#{id}, #{nick}, #{icon}, #{userId}, #{password},#{property})")
    int insertUser(User user);

    /**
     * 通过ID查询用户
     * @param userId
     * @return
     */
    @Select("select id,nick,icon,user_id as userId , password,property from t_user where user_id = #{userId}")
    User selectUserByUserId(int userId);
    /**
     * 通过账号删除用户
     * @param userId
     * @return 修改的条数
     */
    @Delete("delete from t_user where user_id = #{userId}")
    int deleteUserByUserId(int userId);

    /**
     * 更新数据
     * @param user
     * @return 修改的条数
     */
    @Update("update t_user set nick=#{nick},icon=#{icon},password=#{password},property=#{property} where user_id=#{userId}")
    int updateUser(User user);

    /**
     * 查询所有用户
     * @return 用户列表
     */
    @Select("select id,nick,icon,user_id as userId , password,property from t_user")
    List<User> selectAllUser();
}
